<?php

defined('SYSPATH') or die('Access error!');

class Model_Q2a_Tag extends Model
{

    /**
     *  根据tag的 获取tag信息
     * @param type $name
     * @return type
     */
    public function get_tag_by_name($name)
    {
        $tag_detail = $this->get_row(array('name' => $name), 'id,post_count');
        return count($tag_detail) > 0 ? $tag_detail : array();
    }


    public function update_tag_post_count($name, $count)
    {
        $this->update(array('post_count' => $count + 1), array('name' => $name));
    }

    public function get_hot_question_tags($id = '', $setting)
    {
        $q2a_show_tag_num = intval($setting['q2a_show_tag_num']);
        $tag_num = $q2a_show_tag_num == 0 ? 10 : $q2a_show_tag_num;
        $where = !empty($id) ? ' AND ' . 'category_id=' . $id : '';
        $where .= ' ORDER BY post_count DESC,id DESC';
        $where .=' LIMIT ' . $tag_num;
        return $this->get_results($where);
    }

    public function get_tag_list($id = '')
    {
        $where = !empty($id) ? ' AND ' . 'category_id=' . $id : '';
        $where .= ' ORDER BY post_count DESC,id DESC';
        return $this->get_results($where,'id,name,post_count');
    }

}